/*xz19Hnz0vyifyMdV+FdCT6DQz7H60YQRX6+ikas3JfIGsMxqycjBM1bv1t63Ou7W*/
//**********************
//* 单据联查到固定资产卡片
//**********************
import { cacheTools, ajax } from 'nc-lightapp-front';

import constants from '../../constants';
import { listQueryBackHandler } from './commonHandler';
import fa from 'fa';
import ampub from 'ampub';
const { fa_utils: { URLParamUtil: { getUrlParamByPrivateUse } } } = fa;

const { commonConst: { CommonKeys: { linkQueryConst } }, utils: { listUtils: { listConst } } } = ampub;

const { URL, PAGE_CODE } = constants;

//处理其他单据联查卡片到列表态
function linkedQueryByBill(props) {
	// 1 判断是否来源于 预算联查
	let pk_ntbparadimvo = getUrlParamByPrivateUse.call(this, 'pk_ntbparadimvo');
	//判断是否是通过预算联查跳转过来的页面
	if (pk_ntbparadimvo) {
		let param = {
			pagecode: PAGE_CODE.LIST,
			templateid: this.templateid,
			pk_ntbparadimvo
		};
		ajax({
			url: URL.QueryaboutByBudget,
			data: param,
			success: (res) => {
				listQueryBackHandler.success.call(this, props, res, listConst.SETVALUETYPE.default);
			},
			error: (err) => {
				listQueryBackHandler.error(props, err);
			}
		});
	} else {
		// 2 通过联查场景联查
		//获取联查场景
		let scene = props.getUrlParam(linkQueryConst.SCENE);
		if (scene === linkQueryConst.SCENETYPE.linksce) {
			let linkParam = cacheTools.get('fa_facard_linkQuery_param');
			let pks = linkParam['pk_cards'];
			//删除缓存
			cacheTools.remove('fa_facard_linkQuery_param');
			if (pks && pks.length) {
				let param = {
					allpks: pks,
					pagecode: PAGE_CODE.LIST
				};
				ajax({
					url: URL.QUERY_LIST_BYPKS_LINKED,
					data: param,
					success: (res) => {
						listQueryBackHandler.success.call(this, props, res, listConst.SETVALUETYPE.default);
					},
					error: (err) => {
						listQueryBackHandler.error(props, err);
					}
				});
			}
		}
	}
}

//通过凭证联查单据
function linkedQueryByVoucher(props, linkQueryInfo) {
	ajax({
		url: URL.QUERY_LIST_BYPKS_LINKED,
		data: linkQueryInfo,
		success: (res) => {
			listQueryBackHandler.success.call(this, props, res, listConst.SETVALUETYPE.default);
		},
		error: (err) => {
			listQueryBackHandler.error(props, err);
		}
	});
}

export { linkedQueryByVoucher, linkedQueryByBill };

/*xz19Hnz0vyifyMdV+FdCT6DQz7H60YQRX6+ikas3JfIGsMxqycjBM1bv1t63Ou7W*/